/*
 * @description: 真实环境动态请求
 * @Author: Islands
 * @Date: 2024-03-24 16:07:28
 * @LastEditTime: 2024-03-25 20:09:57
 */
import { request, axiosRequest } from '../index';
import { AxiosPromise } from "axios";
import { ILoginData, LoginResult } from './types';
import { Base64 } from 'js-base64'
import { IUserInfo, IRoutes, IMeta } from '@/axios/login/types.d';

const evn = import.meta.env.MODE;
/**
 * 登录
 * @param _loginForm 
 * @returns LoginResult
 */
export function loginApi(_loginForm: ILoginData): AxiosPromise<LoginResult> {
    if (evn == 'test') {
        return request({
            url: "/src/mock/token.json",
            method: "get",
        });
    } else {
        const data = {
            grant_type: 'password',
            username: _loginForm.username,
            password: _loginForm.password,
        };
        return request({
            url: "/oauth/token",
            method: "post",
            data: data,
            auth: {
                username: 'yang',
                password: 'yang_secret'
            }
        });
    }



};


/**
 * 获取登录用户信息
 * @returns  IUserInfo
 */
export function getUserInfoApi(): AxiosPromise<IUserInfo> {
    if (evn === 'test') {
        return request({
            url: "/src/mock/index.json",
            method: "get",
        });
    } else {
        return request({
            url: "/user/info",
            method: "get",
        });
    }

}

/**
 * 获取路由
 * @returns 
 */
export function getRoutesApi(): AxiosPromise<IRoutes<IMeta>> {
    if (evn == 'test') {
        return request({
            url: "/src/mock/routes/index.json",
            method: "get",
        });
    } else {
        return request({
            url: "/menu/routes",
            method: "get",
        });
    }

}